$(function(){
    $.get('http://localhost:1234/head',(data)=>{
        $('#top').append(data)
        $.get('http://localhost:1234/index',(data)=>{
            log(data)
        })
    })
})



function log(data){
    data.forEach(item => {
        let html=`
        <tr id="html">
        <td>${item.id}</td>
        <td>${item.title}</td>
        <td>${item.abstract}</td>
        <td>${item.content}</td>
        <td>${item.classify}</td>
        <td>${item.author}</td>
        <td>${item.dateline}</td>
        <td>
        <input type="button" value="修改" onclick="Edit(${item.id})">
        <input type="button" value="删除" onclick="Delete(${item.id})">
        </td>
        </tr>
        `
        $('#content').append(html)
    });
}


function Delete(id) {
    if (confirm('是否要删除该条数据')) {
        $.get('http://localhost:1234/delete?id=' + id, (data) => {
            let tr = $('tr').length
            for (let i = 0; i < tr; i++) {
                $('#html').remove()
            }
            log(data);

        })
    }
}

function add(){
    
    $.get('http://localhost:1234/add',(data)=>{
        $('#top2').append(data)
    })
}